package course.util;
import java.util.Optional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;

import course.domain.CourseAttribute;
import course.repository.CourseAttributeRepository;

@Component
public class CourseAttributeByIdConverter implements Converter<String, CourseAttribute>{
	private  CourseAttributeRepository  CourseAttributeRepo;

	  @Autowired
	  public CourseAttributeByIdConverter( CourseAttributeRepository  CourseAttributeRepo) {
	    this. CourseAttributeRepo =  CourseAttributeRepo;
	  }
	  
	  @Override
	  public  CourseAttribute convert(String id) {
		  Optional< CourseAttribute> optionalCourseAttribute =  CourseAttributeRepo.findById(id);
			return optionalCourseAttribute.isPresent() ?
				   optionalCourseAttribute.get() : null;
	  }
}
